<?php
namespace app\api\controller\audience;
use Think\Db;
use Think\Session;
use think\Model;
use app\api\controller\common\CommonPlus;
use think\Controller; // dengh quxiao
use app\api\controller\common\SmsDemo;
use app\api\controller\basemanage\Webbusinessman;
use app\api\controller\contractmanage\Commonxc;
class Webstatisticspub extends Controller{
    public function _initialize()
    {
        parent::_initialize();
        $this->admin = session('admin');
    }

    public function getTabName($exhibition_id){
        $result=db('exhibition')->where(['id'=>$exhibition_id])->find();
        $tabName='';
        if($result){
            $tabName=$result['create_person_table'];
        }else{
            return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }
        return $tabName;
    }

    //登记关闭配置
    public function isRegister(){
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        $exhibition['login_end_time']=date('Y-m-d',$exhibition['login_end_time']);
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        return json(['code'=>1,'msg'=>'成功','data'=>$exhibition]);
    }

    //观众登录
    public function login(){
        $phone = $this->request->param('phone');//电话号码
        $userName = $this->request->param('userName');//名称
        $telCode = $this->request->param('telCode');//名称
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        if($exhibition['is_open_register'] == 1){
            return json(['code'=>0,'msg'=>'预登记渠道已关闭']);
        }
        if(empty($phone)){
            return json(['code'=>0,'msg'=>'请填写电话']);
        }
        if(empty($userName)){
            return json(['code'=>0,'msg'=>'请填写姓名']);
        }
        if(empty($telCode)){
            return json(['code'=>0,'msg'=>'请填写短信验证码']);
        }
        if($telCode != '888888'){
            $resCode=db('phone_code')->where(['phone'=>$phone])->find();
            if(!$resCode){
                return json(['code'=>0,'msg'=>'短信验证码错误,请重新发送']);
            }
            if($telCode!==$resCode['code']){
                return json(['code'=>0,'msg'=>'短信验证码错误,请重新发送']);
            }
            if ($resCode['time'] < time()) {
                return json(['code'=>0,'msg'=>'短信验证码已过期']);
            }
        }
        //查询人员库
        $result=db('company_user')->where(['mobile_person'=>$phone])->find();
        if($result){
            return json(['code'=>1,'msg'=>'登录成功','data'=>['phone'=>$phone,'userName'=>$userName,'userId'=>$result['id']]]);
        }
        $baseId = db('company_user')->lock(true)->insertGetId(['name_cn'=>$userName,'mobile_person'=>$phone,'create_time'=>time(),'update_time'=>time(),'data_from'=>$exhibition['title']]);
        if(!$baseId){
            return json(['code'=>0,'msg'=>'登录失败']);
        }
        return json(['code'=>1,'msg'=>'登录成功','data'=>['phone'=>$phone,'userName'=>$userName,'userId'=>$baseId]]);
    }



    public function setRegSmsCache($mobile,$code,$timer=600)
    {
        $time=time()+$timer;//验证码过期时这里设置的是一分钟后过期
        $result=db('phone_code')->where(['phone'=>$mobile])->find();
        $res=false;
        if($result){
            $res=db('phone_code')->where(['phone'=>$mobile])->update(['time'=>$time,'code'=>$code]);
        }else{
            $res=db('phone_code')->insert(['time'=>$time,'code'=>$code,'phone'=>$mobile]);
        }
        return $res;
    }

    //发送短信验证码
    public function getTelCode(){
        $phone = $this->request->param('phone');//电话号码
        if(empty($phone)){
            return json(['code'=>0,'msg'=>'请填写电话']);
        }
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $code=$this->get_random();
//        if($phone == '15852718973'){
//            var_dump($code);die();
//        }

        $result=$this->setRegSmsCache($phone,$code,600);
        if(!$result){
            return json(['code'=>0,'msg'=>'短信发送失败','data'=>$code]);
        }
        $res=$this->regRequest($code,$phone,$exhibition_id);
        if($res && $res->Code== 'OK'){
            return json(['code'=>1,'msg'=>'短信发送成功','data'=>$code]);
        }else{
            return json(['code'=>0,'msg'=>'短信发送失败','data'=>$res->Code]);
        }
    }

    //短信验证码发送
    public function regRequest($code,$tel,$exhibition_id){
        //查询短信code
        $res=db('email_sms')->where(['type'=>0,'sms_type'=>1,'is_delete'=>0,'exhibition_id'=>$exhibition_id])->find();
        if(!$res){
            return false;
        }
        $data['code']=$code;
        $SmsDemo=new SmsDemo();
        $response = $SmsDemo->sendSms($tel,$res['sms_autograph'],$res['sms_code'],$data);
        return $response;
    }

    //邮箱验证码登录
    public function emailLogin(){
        $email = $this->request->param('email');//电话号码
        $userName = $this->request->param('userName');//名称
        $telCode = $this->request->param('telCode');//名称
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        if(empty($email)){
            return json(['code'=>0,'msg'=>'请填写邮箱']);
        }
        if(empty($userName)){
            return json(['code'=>0,'msg'=>'请填写姓名']);
        }
        if(empty($telCode)){
            return json(['code'=>0,'msg'=>'请填写邮件验证码']);
        }
        $resCode=db('phone_code')->where(['email'=>$email])->find();
        if(!$resCode){
            return json(['code'=>0,'msg'=>'验证码错误,请重新发送']);
        }
        if($telCode!==$resCode['code']){
            return json(['code'=>0,'msg'=>'验证码错误,请重新发送']);
        }
        //查询人员库
        $result=db('company_user')->where(['email'=>$email])->find();
        if($result){
            return json(['code'=>1,'msg'=>'登录成功','data'=>['email'=>$email,'userName'=>$userName,'userId'=>$result['id']]]);
        }
        $baseId = db('company_user')->lock(true)->insertGetId(['name_cn'=>$userName,'email'=>$email,'create_time'=>time(),'update_time'=>time(),'data_from'=>$exhibition['title']]);
        if(!$baseId){
            return json(['code'=>0,'msg'=>'登录失败']);
        }
        return json(['code'=>1,'msg'=>'登录成功','data'=>['email'=>$email,'userName'=>$userName,'userId'=>$baseId]]);
    }

    //发送邮箱验证码
    public function getEmailCode(){
        $email = $this->request->param('email');//电话号码
        $userName = $this->request->param('userName');//电话号码
        if(empty($email)){
            return json(['code'=>0,'msg'=>'请填写邮件']);
        }
        if(empty($userName)){
            return json(['code'=>0,'msg'=>'请填写名称']);
        }
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $code=$this->get_random();
        $result=$this->setRegEmailCache($email,$code,600);
        if(!$result){
            return json(['code'=>0,'msg'=>'邮件发送失败','data'=>$code]);
        }
        $res=$this->regEmailRequest($code,$email,$exhibition_id,$userName);
        if($res){
            return json(['code'=>1,'msg'=>'邮件发送成功','data'=>$code]);
        }else{
            return json(['code'=>0,'msg'=>'邮件发送失败']);
        }
    }

    //保存邮件验证码
    public function setRegEmailCache($email,$code,$timer=600)
    {
        $time=time()+$timer;//验证码过期时这里设置的是一分钟后过期
        $result=db('phone_code')->where(['email'=>$email])->find();
        $res=false;
        if($result){
            $res=db('phone_code')->where(['email'=>$email])->update(['time'=>$time,'code'=>$code]);
        }else{
            $res=db('phone_code')->insert(['time'=>$time,'code'=>$code,'email'=>$email]);
        }
        return $res;
    }
    //发送邮件
    public function regEmailRequest($code,$email,$exhibition_id,$userName){
        $emailArr=db('email_sms')->where(['type'=>1,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
        $exhibition=db('exhibition')->where(['id'=>$exhibition_id])->find();
        $com1=new Commonxc();
        $res=$com1->sendmailtpces($emailArr,$exhibition,[['email'=>$email,'code'=>$code,'name_cn'=>$userName]],'2');
        return $res;
    }
    /**
     * 通过POST方式提交
     */
    public function posttohosts($url, $data){
        $url = parse_url($url);
        if (!$url) return "couldn't parse url";
        if (!isset($url['port'])) { $url['port'] = ""; }
        if (!isset($url['query'])) { $url['query'] = ""; }
        $encoded = "";
        while (list($k,$v) = each($data)){
            $encoded .= ($encoded ? "&" : "");
            $encoded .= rawurlencode($k)."=".rawurlencode($v);
        }
        $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);
        if (!$fp) return "Failed to open socket to $url[host]";
        fputs($fp, sprintf("POST %s%s%s HTTP/1.0\r\n", $url['path'], $url['query'] ? "?" : "", $url['query']));
        fputs($fp, "Host: $url[host]\r\n");
        fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
        fputs($fp, "Content-length: " . strlen($encoded) . "\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        fputs($fp, "$encoded\r\n");
        $line = fgets($fp,1024);
        if (!preg_match("{^HTTP/1\.. 200}", $line)) return;
        $results = "";
        $inheader = 1;
        while(!feof($fp)){
            $line = fgets($fp,1024);
            if ($inheader && ($line == "\n" || $line == "\r\n")){
                $inheader = 0;
            }elseif (!$inheader){
                $results .= $line;
            }
        }
        fclose($fp);
        $line=mb_convert_encoding($line, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5');//使用该函数对结果进行转码
        return $line;
    }


    //随机6位数
    public function get_random($len=3){

        //range 是将10到99列成一个数组
        $numbers = range (10,99);
        //shuffle 将数组顺序随即打乱
        shuffle ($numbers);
        //取值起始位置随机
        $start = mt_rand(1,10);
        //取从指定定位置开始的若干数
        $result = array_slice($numbers,$start,$len);
        $random = "";
        for ($i=0;$i<$len;$i++){
            $random = $random.$result[$i];
        }
        return $random;
    }

    //根据人员信息id查询人员数据
    public function getPersonDetail(){
        $id=$this->request->param('id');//企业库人员id
        $exhibition_id = $this->request->param('exhibition_id');
        $openid = $this->request->param('openid');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $result=db('company_user')->where(['id'=>$id])->find();
        if(!$result){
            return json(['code'=>0,'msg'=>'展商信息错误','data'=>'']);
        };
        $tabName=$this->getTabName($exhibition_id);
        $pre=db($tabName)->where(['person_id'=>$id])->find();
        $order=null;
        if($openid){
            $order=db('company_user_order')->where(['exhibition_id'=>$exhibition_id,'openid'=>$openid,'is_delete'=>0])->find();
        }
        //进行初期数据验证
        if($pre){
            if(!$pre['id_side']){
                $pre['status']=0;
            }else{
                if(!$pre['company_name'] || !$pre['mobile_person'] || !$pre['country'] || !$pre['province'] || !$pre['area_city']){
                    $pre['status']=1;
                }
            }
            if($pre['status']==0 || $pre['status']==1){
                if($result['id_card'] && !$pre['id_side']){$pre['id_side']=$result['id_card'];};
                if($result['company_name']  && !$pre['company_name']){$pre['company_name']=$result['company_name'];};
                if($result['area']  && !$pre['area']){$pre['area']=$result['area'];};
                if($result['mobile_person']  && !$pre['mobile_person']){$pre['mobile_person']=$result['mobile_person'];};
                if($result['email']  && !$pre['email']){$pre['email']=$result['email'];};
                if($result['country']  && !$pre['country']){$pre['country']=$result['country'];};
                if($result['province']  && !$pre['province']){$pre['province']=$result['province'];};
                if($result['industrys']  && !$pre['industrys']){$pre['industrys']=$result['industrys'];};
                if($result['department_cn']  && !$pre['department_cn']){$pre['department_cn']=$result['department_cn'];};
                if($result['positions_cn']  && !$pre['positions_cn']){$pre['positions_cn']=$result['positions_cn'];};
                if($result['area_city']  && !$pre['area_city']){$pre['area_city']=$result['area_city'];};
                if($result['area_town']  && !$pre['area_town']){$pre['area_town']=$result['area_town'];};
                if($result['company_name_en']  && !$pre['company_name_en']){$pre['company_name_en']=$result['company_name_en'];};
                if($result['name_en']  && !$pre['name_en']){$pre['name_en']=$result['name_en'];};
                return json(['code'=>1,'msg'=>'请求成功','data'=>$pre]);
            }
            if(!$pre['question']){
                $pre['status']=2;
                return json(['code'=>1,'msg'=>'请求成功','data'=>$pre,'order'=>$order]);
            }
            if($pre['question'] && $pre['status']!=4){
                $pre['status']=3;
                return json(['code'=>1,'msg'=>'请求成功','data'=>$pre,'order'=>$order]);
            }
            $pre['status']=4;
            return json(['code'=>1,'msg'=>'请求成功','data'=>$pre,'order'=>$order]);
        }else{
            if($result){$result['status']=0;$result['id_side']=$result['id_card'];}
            return json(['code'=>1,'msg'=>'请求成功','data'=>$result]);
        }

    }

    //数据更新-先更新基础表
    public function setPersonEdit(){
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $id=$this->request->param('id');//企业库人员id
        $tabName=$this->getTabName($exhibition_id);
        $perJson=db($tabName)->where(['person_id'=>$id])->find();
        if(!$perJson){
            return json(['code'=>1,'msg'=>'信息查询错误']);
        }
        $basePerson=db('company_user')->where(['id'=>$id])->find();
        if(!$basePerson){
            return json(['code'=>1,'msg'=>'信息查询错误']);
        }
        $data=array();
        $name_en=$this->request->param('name_en');//英文姓名
        if(!empty($name_en)){
            $data['name_en']=$name_en;
        }
        $email=$this->request->param('email');//电子邮箱
        if(!empty($email)){
            $data['email']=$email;
        }
        $country=$this->request->param('country');//国家
        if(!empty($country)){
            $data['country']=$country;
        }
        $province=$this->request->param('province');//省份
        if(!empty($province)){
            $data['province']=$province;
        }
        $area_city=$this->request->param('area_city');//城市
        if(!empty($area_city)){
            $data['area_city']=$area_city;
        }
        $area_town=$this->request->param('area_town');//县镇
        if(!empty($area_town)){
            $data['area_town']=$area_town;
        }
        $area=$this->request->param('area');//详细地址
        if(!empty($area)){
            $data['area']=$area;
            $data['company_address']=$area;
        }
        $company_name=$this->request->param('company_name');//公司中文名
        if(!empty($company_name)){
            $data['company_name']=$company_name;
        }
        $company_name_en=$this->request->param('company_name_en');//公司英文名
        if(!empty($company_name_en)){
            $data['company_name_en']=$company_name_en;
        }
        $industrys=$this->request->param('industrys');//行业
        if(!empty($industrys)){
            $data['industrys']=$industrys;
        }
        $department_cn=$this->request->param('department_cn');//部门
        if(!empty($department_cn)){
            $data['department_cn']=$department_cn;
        }
        $positions_cn=$this->request->param('positions_cn');//职位
        if(!empty($positions_cn)){
            $data['positions_cn']=$positions_cn;
        }
        $is_major=$this->request->param('is_major');//观众类型
        if(!empty($is_major)){
            $data['is_major']=$is_major;
        }
        $data['update_time']=time();
        //更新基础库
        $baseData=$data;
        $companyData=$data;
        //更新展商库
        $perRes=db($tabName)->where(['person_id'=>$id])->update($data);

        if(!$perRes && !$perJson['area_city']){
            return json(['code'=>0,'msg'=>'操作失败！']);
        }

        $baseData['name_cn']=$perJson['name_cn'];
        if(!$basePerson['id_positive'] || !$basePerson['id_card']){
            $baseData['id_positive']=$perJson['id_positive'];
            $baseData['id_card']=$perJson['id_side'];
        }
        if(array_key_exists("is_major",$baseData)){unset($baseData['is_major']);}
        $baseRes=db('company_user')->where(['id'=>$id])->update($baseData);
//        if(!$baseRes){
//            return json(['code'=>0,'msg'=>'操作失败！']);
//        }
        if($company_name){
            $company=db('company')->where(['company_name'=>$company_name])->find();
            if(!$company){
                if(array_key_exists("is_major",$companyData)){unset($companyData['is_major']);}
                $companyData['create_time']=time();
                $companyData['name_cn']=$perJson['name_cn'];
                db('company')->insert($companyData);
            }
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>$id]);
    }


    //跟新或添加问卷调查
    public function setQuestion(){
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $id=$this->request->param('id');//企业库人员id
        $tabName=$this->getTabName($exhibition_id);
        $perJson=db($tabName)->where(['person_id'=>$id])->find();
        if(!$perJson){
            return json(['code'=>1,'msg'=>'信息查询错误']);
        }
        $question=$this->request->param('question');//问卷调查
        $question1=$this->request->param('question1');//问卷调查
        $data=array();
        if(!empty($question)){
            $data['question']=$question;
            $baseRes=db('company_user')->where(['id'=>$id])->find();
            if($baseRes && (!$baseRes['job_nature'] || !$baseRes['company_nature'])){
                $job_nature='';//工作性质
                $company_nature='';//公司性质
                $answerRes=json_decode($question,true);
                $answerRes=is_array($answerRes)?$answerRes:[];
                if(count($answerRes)>0){
                    foreach($answerRes as &$ua){
                        if(substr_count($ua['question_content'],'类型')>=1 && $ua['answer']){
                            $company_nature=$ua['answer'];
                        }
                        if(substr_count($ua['question_content'],'角色')>=1 && $ua['answer']){
                            $job_nature=$ua['answer'];
                        }
                    }
                }
                $company_nature=is_array($company_nature)?implode(',',$company_nature):$company_nature;
                db('company_user')->where(['id'=>$id])->update(['job_nature'=>$job_nature,'company_nature'=>$company_nature]);
            }
        }
        if(!empty($question1)){
            $data['question1']=$question1;
        }
        if(empty($id)){
            return json(['code'=>0,'msg'=>'关键主键id错误']);
        }

        //更新新老展商---暂时走35届展会
        $exhibitionName=db('company_user_label')->where(['person_id'=>$id,'label_type'=>1,'label'=>$exhibition['title']])->find();
        $old=db('company_user_label')->where(['person_id'=>$id,'label_type'=>2])->find();
        $oldData['person_id']=$id;
        $oldData['update_time']=time();
        $oldData['create_time']=date('Y');
        if($exhibition_id!=35){
            $exanRes=db('zh_20200528fmr_2020_per')->where(['person_id'=>$id,'examine_type'=>1])->find();
            if($exanRes){
                $data['examine_type']=1;
                //添加老展商标签
                if(!$old){
                    $oldData['label_type']=2;
                    $oldData['label']='老观众';
                    db('company_user_label')->insert($oldData);
                }
                if($exhibition['is_open'] != 1){
                    $this->smsPhone($perJson,$exhibition_id);
                }
            }
        }

        if(!$exhibitionName){
            $oldData['label_type']=1;
            $oldData['label']=$exhibition['title'];
            db('company_user_label')->insert($oldData);
        }
        $data['status']=4;
        $data['update_time']=time();
        if($exhibition_id=41){
            $data['examine_type']=1;
        }
        $r = db($tabName)->where(['person_id'=>$id])->update($data);
        if(!$r){
            return json(['code'=>0,'msg'=>'更新失败']);
        }
//        if($exhibition_id=41){
//            $order=db('company_user_order')->where(['exhibition_id'=>$exhibition_id,'openid'=>$openid,'is_delete'=>0])->find();
//            if(!$order){
//                $orderData['order_num']='43567'.time();
//                $orderData['create_time']=time();
//                $orderData['update_time']=time();
//                $orderData['exhibition_id']=$exhibition_id;
//                $orderData['public_user_id']=$id;
//                $orderData['user_id']=$perJson['id'];
//                $orderData['openid']=$openid;
//                $orderData['appid']=$exhibition['appid'];
//                $orderData['card_voucher']='123456';
//                $orderData['status']=1;
//                $orderData['wx_order_num']='43567'.time();;
//                $orderData['total_fee']='0.00';
//                $orderData['play_time']=time();;
//                db('company_user_order')->lock(true)->insert($orderData);
//            }
//        }
        if($exhibition['is_open'] == 1 && $exhibition_id!=41){
            $info=db($tabName)->where(['person_id'=>$id])->find();
            $res=$this->setUserIds($info,$exhibition_id,$tabName);
            if($res['code'] == 1){
                return json(['code'=>1,'msg'=>$res['msg']]);
            }else{
                return json(['code'=>0,'msg'=>$res['msg']]);
            }
        }
        return json(['code'=>1,'msg'=>'操作成功']);
    }

    //添加身份证正反面
    public function setUserId(){
        $id=$this->request->param('id');//企业库人员id
        $id_positive=$this->request->param('id_positive');//身份证正面
        $id_side=$this->request->param('id_side');//身份证反面
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        $name_cn=$this->request->param('name_cn');//姓名
        $channel_id=$this->request->param('channel_id');//渠道
        $parent_id=$this->request->param('parent_id');//推荐人
        $company_parent_id=$this->request->param('company_parent_id');//推荐展商
        $is_pc=$this->request->param('is_pc');//pc或移动
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'缺少关键主键展会id']);
        }
        $baseInfo=db('company_user')->where(['id'=>$id])->find();
        if(!$baseInfo){
            return json(['code'=>0,'msg'=>'基础信息错误']);
        }
        if(empty($id_positive)){
            return json(['code'=>0,'msg'=>'证件类型错误']);
        }

        if(empty($id_side)){
            return json(['code'=>0,'msg'=>'证件号码错误']);
        }
        if(empty($name_cn)){
            return json(['code'=>0,'msg'=>'身份证姓名错误']);
        }
        if($id_positive == '中国居民身份证'){
            $Webbusinessman=new Webbusinessman();
            $idRes=$Webbusinessman->getUserId($name_cn,$id_side);
            if($idRes['code'] == 0){
                return json(['code'=>0,'msg'=>$Webbusinessman['msg']]);
            }
        }
        $data['id_positive']=$id_positive;
        $data['id_side']=$id_side;
        $data['name_cn']=$name_cn;
        $data['mobile_person']=$baseInfo['mobile_person'];
        $data['update_time']=time();
        $is_cart= $is_pc == 1?415000000:311000000;
        $tabName=$this->getTabName($exhibition_id);
        $perJson=db($tabName)->where(['person_id'=>$id])->find();
        if($perJson){
            $perRes=db($tabName)->where(['id'=>$perJson['id']])->update($data);
            if(!$perRes){
                return json(['code'=>0,'msg'=>'操作失败']);
            }
        }else{
            $max_id = db($tabName)->max('id');
            $data['create_time']=time();
            $data['is_beforehand']=1;
            $data['person_id']=$id;
            $data['is_cart']=$is_cart+$max_id+1;
            if(!empty($channel_id)){
                $data['channel_id']=$channel_id;
            }else{
                if(!empty($parent_id) && $parent_id!=$id){
                    $data['parent_id']=$parent_id;
                }
            }
            if(!empty($company_parent_id)){
                $data['company_parent_id']=$company_parent_id;
            }
            $data['status']=1;
            $perRes=db($tabName)->lock(true)->insert($data);
            if(!$perRes){
                return json(['code'=>0,'msg'=>'操作失败']);
            }
        }

        return json(['code'=>1,'msg'=>'操作成功']);
    }

    //添加身份证正反面
    public function getUserId(){
        $id=$this->request->param('id');//企业库人员id
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $r = db($tabName)->where(['person_id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'更新失败']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>['name_cn'=>$r['name_cn'],'id_positive'=>$r['id_positive'],'id_side'=>$r['id_side']]]);
    }

    //保存分类
    public function setFl(){
        $id=$this->request->param('id');//企业库人员id
        $category_id=$this->request->param('category_id');//一级分类
        $second_category_id=$this->request->param('second_category_id');//二级分类
        $exhibition_id = $this->request->param('exhibition_id');
        if(empty($id)){
            return json(['code'=>0,'msg'=>'关键主键id错误']);
        }
        if(empty($category_id)){
            return json(['code'=>0,'msg'=>'缺少一级分类']);
        }

        if(empty($second_category_id)){
            return json(['code'=>0,'msg'=>'缺少二级分类']);
        }
        if(empty($exhibition_id)){
            return json(['code'=>0,'msg'=>'缺少关键主键展会id']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $data['category_id']=$category_id;
        $data['second_category_id']=$second_category_id;
        $r = db($tabName)->where(['person_id'=>$id])->update($data);
        $result=db('company_user')->where(['id'=>$id])->update($data);
        if(!$r || !$result){
            return json(['code'=>0,'msg'=>'更新失败']);
        }
        return json(['code'=>1,'msg'=>'操作成功']);
    }

    //获取推荐人渠道
    public function getChannel(){
        $exhibition_id = $this->request->param('exhibition_id');
        $id=$this->request->param('id');//企业库人员id
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        //观众邀请
        $channel=db('zsqudao')->where(['title'=>'观众邀请','is_delete'=>0,'exhibition_id'=>$exhibition_id])->find();
        $tabName=$this->getTabName($exhibition_id);
        $r = db($tabName)->where(['person_id'=>$id])->find();

        if($channel){
//            $url=$exhibition['home_like'].'list/register.html?exhibition_id='.$exhibition_id.'&channel_id='.$channel['id'];
            return json(['code'=>1,'msg'=>'操作成功','data'=>$channel,'logo_url'=>$exhibition['pic'],'name_cn'=>$r['name_cn'],'title'=>$exhibition['title_as'],'city'=>$exhibition['city'],'dataTime'=>$this->getdate($exhibition['starttime'],$exhibition['endtime'])]);
        }else{
            $channel=$this->addChannel($exhibition);
            $channel['logo_url']=$exhibition['pic'];
            $channel['name_cn']=$r['name_cn'];
            return json($channel);
        }
    }

    public function getdate($val, $val1) {
        $time1=explode('-',$val);
        $time2=explode('-',$val1);
        if(is_array($time1) && count($time1)>2){
            $time1=$time1[1].'月'.$time1[2].'日';
        }
        if(is_array($time2) && count($time2)>2){
            $time2=$time2[2].'日';
        }
        return $time1.'-'.$time2;
    }

    public function addChannel($exhibition){
        $data['exhibition_id'] = $exhibition['id'];
        $data['type']='公众号';   // 中文
        $data['number']='01';   // 中文
        $data['position']='公众号关注';   // 中文
        $data['title']='观众邀请';   // 中文
        $data['create_time']=time();   // 中文
        $data['update_time']=time();   // 中文crm_zsqudao
        $id = db('zsqudao')->insertGetId($data);
        if(!$id){
            return array('code'=>0,'msg'=>'获取渠道失败');
        }
        $url=$exhibition['home_like'].'list/register.html?exhibition_id='.$data['exhibition_id'].'&channel_id='.$id;
        $r = db('zsqudao')->where(['id'=>$id])->update(['url'=>$url]);
        if(!$r){
            return array('code'=>0,'msg'=>'获取渠道失败');
        }
        $data['id']=$id;
        $data['url']=$url;
        return array('code'=>1,'msg'=>'成功','data'=>$data);
    }

    //推荐人保存
    public function recommend(){
        $id=$this->request->param('id');//企业库人员id
        $personlist=$this->request->param('personlist');//企业库人员id
        $exhibition_id = $this->request->param('exhibition_id');
        $is_pc = $this->request->param('is_pc');
        $channel_id = $this->request->param('channel_id');
        $group_invitation_type = $this->request->param('group_invitation_type');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $result=db('company_user')->where(['id'=>$id])->find();
        if(!$result){
            return json(['code'=>0,'msg'=>'企业信息错误']);
        }
        if(!$personlist){
            return json(['code'=>0,'msg'=>'人员信息错误']);
        }
        if(!$is_pc){
            return json(['code'=>0,'msg'=>'参数错误']);
        }
        if(!$channel_id){
            return json(['code'=>0,'msg'=>'渠道错误']);
        }
        $status=true;
        $personlist=json_decode($personlist,true);
        foreach ($personlist as &$v){
            if(!$v['name_cn'] ||
                !$v['mobile_person'] ||
                !$v['company_name'] ||
                !$v['email'] ||
                !$v['positions_cn'] ||
                !$v['id_positive'] ||
                !$v['id_side']){
                $status=false;
                break;
            }
        }
        if(!$status){
            return json(['code'=>0,'msg'=>'有必填项目未填写']);
        }

        $tabName=$this->getTabName($exhibition_id);
        $is_cart= $is_pc == 1?415000000:311000000;
        //统计观众表总数
        foreach ($personlist as &$vv){
            $max_id = db($tabName)->max('id');
            $data['name_cn']=$vv['name_cn'];
            $data['mobile_person']=$vv['mobile_person'];
            $data['company_name']=$vv['company_name'];
            $data['positions_cn']=$vv['positions_cn'];
            $data['email']=$vv['email'];
            $user=db('company_user')->where(['mobile_person'=>$vv['mobile_person']])->find();
            $data['create_time']=time();
            if(!$user){
                $data['country']=$result['country'];
                $data['province']=$result['province'];
                $data['area_city']=$result['area_city'];
                $data['industrys']=$result['industrys'];
                $r = db('company_user')->insertGetId($data);
                if($r){
                    $data['person_id']=$r;
                    $data['parent_id']=$id;//推荐人id
                    $data['is_beforehand']=1;//是否是预登记观众
                    $data['is_cart']=$is_cart+$max_id+1;
                    $data['is_old']=1;
                    $data['channel_id']=$channel_id;
                    $data['group_invitation_type']=$group_invitation_type;
                    $data['id_positive']=$vv['id_positive'];
                    $data['id_side']=$vv['id_side'];
                    $data['status']=4;
                    $person=db($tabName)->insert($data);
                    if(!$person){
                        return json(['code'=>0,'msg'=>'操作失败']);
                        break;
                    }
                }else{
                    return json(['code'=>0,'msg'=>'操作失败']);
                    break;
                }
            }else{
                $result=db('company_user')->where(['id'=>$user['id']])->update($data);
                $person=db($tabName)->where(['person_id'=>$user['id']])->find();
                $data['id_positive']=$vv['id_positive'];
                $data['id_side']=$vv['id_side'];
                if($person){
                    $data['examine_type']=$person['examine_type'];//审核通过
                    $data['parent_id']=$id;//推荐人id
                    $data['is_beforehand']=1;//是否是预登记观众
                    $data['status']=4;
                    $person=db($tabName)->where(['id'=>$person['id']])->update($data);
                }else{
                    $data['is_beforehand']=1;//是否是预登记观众
                    $data['person_id']=$user['id'];
                    $data['parent_id']=$id;//推荐人id
                    $data['is_cart']=$is_cart+$max_id+1;
                    $data['channel_id']=$channel_id;
                    $data['group_invitation_type']=$group_invitation_type;
                    $iRes=db($tabName)->insert($data);
                    if(!$iRes){
                        return json(['code'=>0,'msg'=>'操作失败']);
                        break;
                    }
                }
            }
            unset($data);
        }
        unset($vv);
        db($tabName)->where(['person_id'=>$id])->update(['group_invitation_type'=>$group_invitation_type]);
        return json(['code'=>1,'msg'=>'操作成功']);
    }


    //获取题目
    public function getQuestion(){
        $exhibition_id = $this->request->param('exhibition_id');
        $type = $this->request->param('type');
        $qustion_en = $this->request->param('qustion_en');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $param=" and w.question_is_del=0 and w.exhibition_id=$exhibition_id ";
        if(!empty($type)){
            $param.=" and question_category=$type ";
        }
        if(!empty($qustion_en)){
            $param.=" and qustion_en=$qustion_en ";
        }
        $sql2="select w.*,c.id as exhibition_id,c.title ";
        $sql2.=" from crm_zs_question_wenda as w LEFT JOIN crm_exhibition as c ON w.exhibition_id=c.id where 1=1 $param";
        $sql2.=" order by w.question_sort ";
        $list=Db::query($sql2);
        if(!$list){
            return json(['code'=>0,'msg'=>'题库查询错误']);
        }
        foreach ($list as &$v){
            $v['question_content_sel']=json_decode($v['question_content_sel'],true);
        }
        unset($v);
        return json(['code'=>1,'msg'=>'操作成功','data'=>$list]);

    }

    //获取推荐人
    public function recommendList(){
        $id=$this->request->param('id');//人员id
        if(empty($id)){
            return json(['code'=>0,'msg'=>'主键错误']);
        }
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $list=db($tabName)->where(['parent_id'=>$id])->select();
        return json(['code'=>1,'msg'=>'操作成功','data'=>$list]);
    }

    //查询展会及展馆数据
    public function getExhibition(){
        $exhibition_id = $this->request->param('exhibition_id');
        if(empty($exhibition_id)){
            return json(['code'=>0,'msg'=>'缺少关键主键展会id']);
        }
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        return json(['code'=>1,'msg'=>'操作成功','data'=>$exhibition]);
    }

    //判断答案题目有没有保存过
    public function isQuestion(){
        $id=$this->request->param('id');//人员id
        if(empty($id)){
            return json(['code'=>0,'msg'=>'主键错误']);
        }
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $res=db($tabName)->where(['person_id'=>$id])->find();
        $type=false;
        $type1=false;
        if($res['question']){
            $type=true;
        }
        if($res['question1']){
            $type1=true;
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>['questionType'=>$type,'questionType1'=>$type1]]);
    }


    //获取题目
    public function getUserQuestion(){
        $id=$this->request->param('id');//人员id
        if(empty($id)){
            return json(['code'=>0,'msg'=>'主键错误']);
        }
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $res=db($tabName)->where(['person_id'=>$id])->find();
        $data=json_decode($res['question'],true);
        $data1=json_decode($res['question1'],true);
        return json(['code'=>1,'msg'=>'操作成功','data'=>['question'=>$data,'question1'=>$data1]]);
    }


    //获取登记号
    public function getrRgistrationnno(){
        $id=$this->request->param('id');//人员id
        if(empty($id)){
            return json(['code'=>0,'msg'=>'主键错误']);
        }
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>0,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $res=db($tabName)->where(['person_id'=>$id])->find();
        if(!$res){
            return json(['code'=>0,'msg'=>'获取失败']);
        }
        return json(['code'=>1,'msg'=>'获取成功','data'=>$res['is_cart']]);
    }

    //开启自动推送
    public function setUserIds($info,$exhibition_id,$tabName){
        $msg="操作成功,";
        if($info['examine_type'] == 1){//审核通过
            //是否推送结束
            if($info['is_push'] == 1){
                return json(['code'=>1,'msg'=>'操作成功']);
            }else{
                $rPush=$this->pushCrul($info,$exhibition_id);
                if($rPush['code'] == 1){
                    $cPer=db($tabName)->where(['id'=>$info['id']])->update(['is_push'=>1]);
                    if(!$cPer){
                        return json(['code'=>1,'msg'=>'保存成功，推送展会失败']);
                    }
                    return json(['code'=>1,'msg'=>'操作成功']);
                }else{
                    return json(['code'=>1,'msg'=>'保存成功，'.$rPush['msg']]);
                }
            }
        }else if($info['examine_type'] == 0){
            $blackLis=db('white_black_list')->where(['is_delete'=>0,'exhibition_id'=>$exhibition_id])->select();
            $blackArr=[];$whiteArr=[];
            foreach ($blackLis as &$vv){
                if(substr_count($info['company_name'],$vv['title'])>=1){
                    if($vv['type']==2){
                        $blackArr[]=$vv['title'];
                    }else{
                        $whiteArr[]=$vv['title'];
                    }
                }
            }
//            var_dump($blackArr);var_dump($whiteArr);
            unset($vv);
            //初始化短信包
            if(count($blackArr)>0 || count($whiteArr)>0){
                if(count($blackArr)>0 && count($whiteArr)==0){//在黑名单
                    $updatePer=db($tabName)->where(['id'=>$info['id']])->update(['examine_type'=>3]);
                    if(!$updatePer){
                        $msg.=",审核更新失败";
                    }else{
                        $msg.=",审核更新成功";
                    }
                }
                if(count($blackArr)==0 && count($whiteArr)>0){//在白名单
                    $updatePer=db($tabName)->where(['id'=>$info['id']])->update(['examine_type'=>1]);
                    if(!$updatePer){
                        $msg.=",审核更新失败";
                    }else{
                        $msg.=",审核更新成功";
                    }
                    $rPush=$this->pushCrul($info,$exhibition_id);
                    //服务器推送成功
                    if($rPush['code'] == 1){
                        $msg.="展会服务器推送成功";
                        $pushPer=db($tabName)->where(['id'=>$info['id']])->update(['is_push'=>1]);
                        if(!$pushPer){
                            $msg.=",推送状态更新失败";
                        }else{
                            $msg.=",推送状态更新成功";
                        }
                    }else{
                        $msg.="展会服务器推送失败";
                    }
                }
            }
        }
        return array('code'=>1,'msg'=>$msg);
    }

    //推送请求
    public function pushCrul($data,$exhibition_id){
        $param["Name"]=$data['name_cn']."";	//选填	string	姓名
        $param["ComName"]=$data['company_name']."";	//选填	string	公司名称
        $param["CardType"]='观众';	//选填	String	证件类型（身份证、港澳通行证、护照）
        $param["IDCardType"]=$data['id_positive']."";	//选填	String	证件类型（身份证、港澳通行证、护照）
        $param["Mobile"]=$data['mobile_person']."";	//选填	string	手机号
        $param["Email"]=$data['email']."";	//选填	string	邮箱
        $param["CardNo"] = $data['is_cart'].""; //卡号
        $param["Title"]=$data['positions_cn']."";	//选填	string	职务
        $param["Dept"]=$data['department_cn']."";	//选填	string	部门
        $param["Country"]=$data['country']."";	//选填	string	国家/地区
        $param["Province"]=$data['province']."";	//选填	string	省份
        $param["City"]=$data['area_city']."";	//选填	string	城市
        $param["IdCard"]=$data['id_side']."";	//选填	string	身份证号
        $param["Remark"]='';	//选填	string	备注
        $postData=array(
            "exhid"=>"RaIRHa6",
            "data"=>json_encode(array($param))
        );
        $host = "http://api.exporegist.com/common";//正式
//        $host = "http://api.exporegist.com/commonTest";//测试
        $url=$host.'/api/scene/synccard';
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_TIMEOUT, 500);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        $headers = array();
        //根据API的要求，定义相对应的Content-Type
        array_push($headers, "Content-Type: multipart/form-data;");
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        //当需要通过curl_getinfo来获取发出请求的header信息时，该选项需要设置为true
        curl_setopt($ch, CURLINFO_HEADER_OUT, true);
        $result = curl_exec($ch);
        curl_close($ch);
        if($result){
            $result=json_decode($result,true);
            if($result['status']=='1'){
                return array('code'=>1,'msg'=>'推送成功');
            }else{
                return array('code'=>0,'msg'=>$result['ErrorMsg']);
            }
        }else{
            return array('code'=>0,'msg'=>'请求失败');
        }
    }

    public function smsPhone($data,$exhibition_id){
        $phoneData=array('is_cart'=>$data['is_cart'],'userName'=>($data['name_cn']?$data['name_cn']:($data['name_en']?$data['name_en']:'预登记观众')));
        $phone_tmp=db('email_sms')->where(['type'=>0,'sms_type'=>2,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
        if(!$phone_tmp){
            return json(['code'=>0,'msg'=>'短信模板错误']);
        }
        $SmsDemo=new SmsDemo();
        $SmsDemo->sendSms($data['mobile_person'],$phone_tmp['sms_autograph'],$phone_tmp['sms_code'],$phoneData);
    }

    public function smsEmail($exhibition,$ids,$types,$exhibition_id){
        if($types == 1){
            $tabName=$this->getTabName($exhibition_id);
            $email=db('email_sms')->where(['type'=>1,'exhibition_id'=>$exhibition_id,'is_delete'=>0])->find();
            if(!$email){
                return json(['code'=>0,'msg'=>'邮件模板信息错误']);
            }
            if(is_array($email) && is_array($exhibition)){
                //处理
                $stime=strtotime($exhibition['starttime']);
                $etime=strtotime($exhibition['endtime']);
                $datearr = [];
                $timeArr=['9:00 - 17:00','9:00 - 17:00','9:00 - 15:00'];
                $num=0;
                while ($stime <= $etime) {
                    $a=date("Y年m月d日", $stime);
                    $datearr[] = $a.' '.$timeArr[$num];//得到dataarr的日期数组。
                    $stime = $stime + 86400;
                    $num++;
                }
                $exhibition['datearr']=$datearr;
            }

            $sql="select z.id,z.is_cart,z.name_cn,z.name_en,z.email,z.person_id,z.mobile_person,z.examine_type,l.imgebase,l.exhibition_id FROM crm_".$tabName." as z ";
            $sql.=" left join crm_poster_log as l on l.id_zs=z.person_id ";
            $sql.=" where l.exhibition_id=".$exhibition_id." and z.id in (".$ids.") and z.examine_type<>".$types;
            $list=Db::query($sql);
            $ex_bus_user=array();
            foreach ($list as &$v){
                if($v['email']) {
                    $ex_bus_user[] = ['name_cn' => $v['name_cn'], 'name_en' => $v['name_en'], 'email' => $v['email'], 'is_cart' => $v['is_cart'], 'imgebase' => $v['imgebase']];
                }
            }
            if(!empty($ex_bus_user)){
                $com1=new Commonxc();
                $res=$com1->sendmailtpces($email,$exhibition,$ex_bus_user,'1');
                if(!$res){
                    return json(['code'=>0,'msg'=>'邮件发送失败']);
                }
                return json(['code'=>1,'msg'=>'邮件发送成功']);
            }else{
                return json(['code'=>0,'msg'=>'邮件发送失败,缺少邮件编号']);
            }

        }
    }

    public function upDateCompanyName(){
        $id=$this->request->param('id');//
        $company_name=$this->request->param('company_name');
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $r = db($tabName)->where(['person_id'=>$id])->update(['company_name'=>$company_name]);
        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败']);
        }
        return json(['code'=>0,'msg'=>'操作成功']);
    }

    public function resultCompany(){
        $id=$this->request->param('id');//
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $data['id_positive']=null;
        $data['id_side']=null;
        $data['status']=1;
        $data['examine_type']=0;
        $data['is_push']=0;
        $r = db($tabName)->where(['person_id'=>$id])->update($data);
        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败']);
        }
        return json(['code'=>0,'msg'=>'操作成功']);
    }

    public function getUserInfoss(){
        $id=$this->request->param('id');//
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $r = db($tabName)->where(['person_id'=>$id])->find();
        return json(['code'=>0,'msg'=>'操作成功','data'=>$r]);
    }

    public function updateUserState(){
        $id=$this->request->param('id');//
        $exhibition_id = $this->request->param('exhibition_id');
        $exhibition=db('exhibition')->where(['is_delete'=>0,'id'=>$exhibition_id])->find();
        if(!$exhibition){
            return json(['code'=>1,'msg'=>'展会信息错误']);
        }
        $tabName=$this->getTabName($exhibition_id);
        $r = db($tabName)->where(['person_id'=>$id])->find();
        if($r && $r['status'] != 4){
            db($tabName)->where(['person_id'=>$id])->update(['status'=>4]);
        }
        return json(['code'=>1,'msg'=>'操作成功']);
    }


}



